package org.mzyyn.qr.service.impl;

import org.mzyyn.qr.dto.setting.SettingDTO;
import org.mzyyn.qr.dto.setting.SettingSaveDTO;
import org.mzyyn.qr.entity.SettingPO;
import org.mzyyn.qr.mapper.SettingMapper;
import org.mzyyn.qr.service.SettingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.qr.xiaocao.common.enums.CommonResultEnum;
import org.qr.xiaocao.exception.ServiceException;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 配置表 服务实现类
 * </p>
 *
 * @author lipeng
 * @since 2024-09-05
 */
@Service
public class SettingServiceImpl extends ServiceImpl<SettingMapper, SettingPO> implements SettingService {

    @Override
    public SettingPO getSetting(SettingDTO settingDTO) {
        return this.baseMapper.selectById(settingDTO.getId());
    }

    @Override
    public void saveSetting(SettingSaveDTO settingSaveDTO) {
        SettingPO settingPO = this.baseMapper.selectById(settingSaveDTO.getId());
        if( null == settingPO ){
            throw new ServiceException(CommonResultEnum.DATA_NOT_EXIST.getCode(),"配置不存在");
        }

        settingPO.setContent(settingSaveDTO.getContent());

        this.baseMapper.updateById(settingPO);
    }
}
